<?php
/**
 *  后台管理控制器基类
 */
namespace App\Http\Controllers\Admin;

use App\Http\Requests;
use Illuminate\Support\Facades\Session;
use Illuminate\Routing\Controller as BaseController;

abstract class AdminBaseController extends BaseController {

//	use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

	/**
	 * Ajax方式返回数据到客户端
	 * @access protected
	 * @param mixed $data 要返回的数据
	 * @param String $type AJAX返回数据格式
	 * @return void
	 */
	public function ajaxReturn($data, $type = '') {
		if (empty($type))
			$type = 'JSON';
		if (strtoupper($type) == 'JSON') {
			// 返回JSON数据格式到客户端 包含状态信息
			header('Content-Type:text/html; charset=utf-8');
			exit(json_encode($data));
		} elseif (strtoupper($type) == 'XML') {
			// 返回xml格式数据
			header('Content-Type:text/xml; charset=utf-8');
			exit(xml_encode($data));
		} elseif (strtoupper($type) == 'EVAL') {
			// 返回可执行的js脚本
			header('Content-Type:text/html; charset=utf-8');
			exit($data);
		} else {
			// TODO 增加其它格式
		}
	}
}